const path = require('path')

/**
 * 获取当前平台
 */
const platform = process.env.UNI_PLATFORM

const isDev = process.env.NODE_ENV === 'development'

/**
 * Vue CLI 配置
 * - @see https://cli.vuejs.org/zh/config
 * uni-app 配置
 * - @see https://uniapp.dcloud.net.cn/collocation/vue-config
 */
module.exports = {
  transpileDependencies: ['@climblee/uv-ui', 'luch-request'],
  configureWebpack: {
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
      // 添加常用扩展名，提高解析速度
      extensions: ['.js', '.json'],
    },
    // 开发环境开启源码映射
    devtool: isDev ? 'source-map' : false,
    // 优化配置
    optimization:
      isDev && platform === 'h5'
        ? {
            splitChunks: {
              chunks: 'all',
            },
          }
        : undefined,
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `@import "@/styles/abstracts/_index.scss";`,
      },
    },
  },
  devServer: {
    port: 8080,
    open: true,
  },
}
